package com.zegome.game.gomestory.main;

import java.util.Locale;
import java.util.Random;
import java.util.Vector;

import android.R.bool;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.facebook.Session;
import com.zegome.game.gomestory.main.helper.BackListener;
import com.zegome.game.gomestory.main.helper.DailyGift;
import com.zegome.game.gomestory.main.helper.GameAdvertise;
import com.zegome.game.gomestory.main.helper.Gift;
import com.zegome.game.gomestory.main.helper.IMAction;
import com.zegome.game.gomestory.main.helper.LazyLoadImage;
import com.zegome.game.gomestory.main.helper.StringHelper;
import com.zegome.game.gomestory.main.scene.BaseGameScreen;
import com.zegome.game.gomestory.main.scene.chapter.ChapterInfo;
import com.zegome.game.gomestory.main.scene.draw.MapInfo;
import com.zegome.game.gomestory.main.scene.level.LevelInfo;
import com.zegome.secure.ExternalFileEncrypt;

public class D {
	
		
	public ExternalFileEncrypt mFile;
	
	public static boolean isChangeAvatar = false;
	
	Center ctr;
	
	public boolean isLogout;
	
	public int level, total_win, total_lose, star;
	public String achievement;
	public int exp;
	public int thang_cap;
	public String coupon;
	
	public boolean isHasAccount=false;
	public boolean isMusic = true;
	public boolean isSound = true;
	public static boolean isTestVersion = false;
	
	public boolean isLogined;	
	public boolean isNetworkAvaiable;
	public boolean isSendingLogin;
	
	public boolean isCheckNotifyAnonymous;
	public boolean isSendingCheckNotifyAnonymous;
	
	public boolean isSendEmail;
	public boolean isSendingEmail;
	
	public boolean isCheckVersion;
	public boolean isSendingCheckVersion;
	public boolean isShowDialogUpdateVersion;
	public boolean isVersionLatest;
	public String messageUpdate;
	public int currentVersion;
	public String packageName;
	
	public boolean isVietnamese;
	public boolean isFirstInVS;
	public boolean isGoogleVersion = false;
	
	public boolean isSendingGetSessionId;
	public boolean isHasSessionId;
		
	public boolean isSendingAvatar;
	public boolean isCheckAvatar;
	
	public String timeAvatar;
	public boolean isNewAvatarNotSync;
	public boolean isSyncingNewAvatar;
	public boolean isSyncedNewAvatar;
	
	public int moneyOnline;
	public int money;
	public String name;	
	public static String nameClone;	
	public String email;
	public String pass;	
	public ChapterInfo[] chapters;	
	public LevelInfo[] levels;
	public Vector<MapInfo> maps;	
	public Vector<BackListener> backLis;
	public int[] maxTypeIcon;
	public int levelDraw = 1;
	public float speedPlay;
	
	public String namePre;	
	public String emailPre;
	public String passPre;	
	
	public Vector<Gift> gifts;
	
	public Vector<DailyGift> dailyGifts;
	
	public String nameB;
	public int levelB, gomeB;
	public String achievementB;
	public int expB,starB, total_winB, total_loseB;
	public float speedB, startB, factorB;
	public int experUp, experUpB;
	public int receive, receiveB;
	
	public String transaction_id;
	
	public boolean isHelpMenuFinish = false;
	public boolean isHelpDraw1, isHelpDraw2;
	
	
	public boolean isLoginedFB;
	
	public boolean isLDPI = true;
	
	public int typeBet;
	public int betNum;
	
	public static final int MENU = 0;
	public static final int VS = 1;
	public static final int DRAW = 2;
	public static final int GAME = 3;
	
	public static final int TASK_FB_FEED = 0;
	public static final int TASK_FB_SHARE = 1;
	public static final int TASK_FB_STORY = 2;
	public static final int TASK_DRAW = 3;
	public static final int TASK_VS = 4;	
	
	public boolean[] passScreen = new boolean[4];
	public boolean[] passTask = new boolean[5];
	public boolean isShowOneTask;
	
	public boolean isNoelWeek = true;
	
	public D(Center ctr){
		this.ctr = ctr;
	}
	
	public void getSpeed(){
		String data = "3.67";
		speedPlay = Float.parseFloat(data);
	}
	
	public void addSpeed(float speed){		
	}
	
	public void saveAvatarInfo(){		
		String data = ctr.d.timeAvatar+"|"+(ctr.d.isNewAvatarNotSync?1:0);
		mFile.savaData("avatar", data);
	}
	
	public void getAvatarInfo(){
		
		String def = "2012-09-24 00:00:01|0";
		//def = null;
		
		String data = mFile.getStringData("avatar", def);
		
		if(data!=null){
			String[] detailts = ctr.stringHelper.split(data, '|');
			ctr.d.timeAvatar = detailts[0];
			ctr.d.isNewAvatarNotSync = detailts[1].equals("0")?false:true;		
			if(ctr.androidHelper.checkFileExist("/sdcard/data/avatar/"+ctr.d.name) == false){
				ctr.d.isNewAvatarNotSync = false;
				ctr.d.timeAvatar = "2012-09-24 00:00:01";
				ctr.d.saveAvatarInfo();
			}
		}
		
		if(Locale.getDefault().getDisplayLanguage().equals("Tiếng Việt")){			
			isVietnamese = true;
		}
		else{
			isVietnamese = false;
		}
		ctr.androidHelper.log(ctr.d.timeAvatar +"--"+ctr.d.isNewAvatarNotSync+"-- Vietnamese:"+isVietnamese);
		
		Session session = Session.getActiveSession();
		if (session != null && session.isOpened()) {
			isLoginedFB = true;
		} else {
			isLoginedFB = false;
		}
		
	}
	
	public void getAccount(){
		String def = null;
			
		String data = mFile.getStringData("account", def);				
		if(data!=null && data.contains("|")){
			String[] detailts = ctr.stringHelper.split(data, '|');
			ctr.d.email = detailts[0];
			ctr.d.name = detailts[1];
			ctr.d.pass = detailts[2];
			ctr.d.money = Integer.parseInt(detailts[3]);			
			isHasAccount = true;
			if(ctr.d.name.equals("")){
				isHasAccount = false;
			}
			ctr.d.moneyOnline = Integer.parseInt(detailts[4]);									
		}
		else{
			isHasAccount = false;		
			ctr.d.email = "";
			ctr.d.name = "";
			ctr.d.pass = "";
			ctr.d.money = 1000;			
			ctr.d.moneyOnline = 0;
			ctr.d.saveAccount();			
		}
		
		
		ctr.d.emailPre = ctr.androidHelper.getEmail();
		
		if(isHasAccount)
			saveSendEmail();
		else
			getSendEmail();
		
		isHelpMenuFinish = ctr.controller.getActivity().getPreference().getBoolean("HelpMenu", false);
		isHelpDraw1 = ctr.controller.getActivity().getPreference().getBoolean("HelpDraw1", true);
		isHelpDraw2 = ctr.controller.getActivity().getPreference().getBoolean("HelpDraw2", true);
		
		isShowOneTask = true;
		
		String temp =  mFile.getStringData("pass_screen", "0|0|0|0");
		String[] dataTemp = ctr.stringHelper.split(temp, '|');		
		for(int i=0;i<4;i++){
			if(dataTemp[i].equals("0")){
				passScreen[i] = false;
			}
			else{
				passScreen[i] = true;
			}
		}
		
	
		temp =  mFile.getStringData("pass_task", "0|0|0|0|0|3");
		//Log.e("AAAAAAA", temp);
		dataTemp = null;
		dataTemp = ctr.stringHelper.split(temp, '|');		
		for(int i=0;i<6;i++){
			if(i==5){
				levelDraw = Integer.parseInt(dataTemp[5]);
				continue;
			}
			if(dataTemp[i].equals("0")){
				passTask[i] = false;
			}
			else{
				passTask[i] = true;
			}
		}	
				
		currentVersion = ctr.androidHelper.getVersionCode();
		
		ctr.d.isNoelWeek = ctr.androidHelper.isChristmasWeek();
		
		getIsLatestVersion();
	}
	
	public void getIsLatestVersion(){
		String temp = ctr.androidHelper.getStringFile("ver", "1| | ");
		String[] details = ctr.stringHelper.split(temp, '|');
		int latest = Integer.parseInt(details[0]);
		if(currentVersion<latest){			
			ctr.d.isVersionLatest = false;
		}
		else{
			ctr.d.isVersionLatest = true;
		}		
		ctr.d.messageUpdate = details[1];
		ctr.d.packageName = details[2];
		ctr.androidHelper.log("LASTEST VERSION "+ latest);
	}
	
	public void saveSendEmail(){
		ctr.androidHelper.saveFile("email", "1");
	}
	
	public void getSendEmail(){
		String temp = ctr.androidHelper.getStringFile("email", "0");
		if(temp.equals("0")){
			isSendEmail = false;
		}
		else{
			isSendEmail = true;
		}
	}
	
	public void saveIsLatestVersion(int latest){
		ctr.androidHelper.saveFile("ver", latest+"|"+ctr.d.messageUpdate+"|"+ctr.d.packageName);
	}
	
	public void saveAccount(){
		String data = email+"|"+name+"|"+pass+"|"+ctr.d.money+"|"+ctr.d.moneyOnline;
		mFile.savaData("account", data);	
		String temp="";
		for(int i=0;i<4;i++){
			if(passScreen[i]){
				if(i !=3 )
				temp+="1|";
				else
					temp+="1";
			}
			else{
				if(i !=3 )
					temp+="0|";
					else
						temp+="0";
			}
		}		
		mFile.savaData("pass_screen", temp);
		
		temp="";
		for(int i=0;i<5;i++){
			if(passTask[i]){
				if(i != 4 )
				temp+="1|";
				else
					temp+="1";
			}
			else{
				if(i !=4 )
					temp+="0|";
					else
						temp+="0";
			}
		}		
		temp+="|"+levelDraw;
		mFile.savaData("pass_task", temp);
	}
	
	public void getDataChapter(){
		getLevel();
		String prevData = null;
		if(ctr.androidHelper.checkFileExist("/sdcard/data/ogme/chapter2.txt")){			
		}
		else{
			if(ctr.androidHelper.checkFileExist("/sdcard/data/ogme/chapter.txt")){				
				prevData = ctr.androidHelper.getStringFile("chapter.txt", "");
			}		
		}
		String data = ctr.androidHelper.getStringFile("chapter2.txt", prevData!=null?prevData+"|7,1,0,0":"0,1,0,0|1,0,36,0|2,0,78,0|3,0,126,0|4,0,180,0|5,0,240,0|6,0,306,0|7,1,0,0");
		TextureRegion[] regions;
		if(data != null && chapters == null){
			String[] chapter = ctr.stringHelper.split(data, '|');
			chapters = new ChapterInfo[chapter.length]; 
			for(int i=0;i<chapter.length;i++){				
				String[] details = ctr.stringHelper.split(chapter[i], ',');				
				boolean isUnlock; 
				int starToUnlock, starCollect;
				isUnlock = Integer.parseInt(details[1])==1;
				starToUnlock = Integer.parseInt(details[2]);
				starCollect = Integer.parseInt(details[3]);
				regions = getChapterIcon(i);				
				chapters[i] = new ChapterInfo("", isUnlock, starToUnlock, starCollect, regions[0], regions[1]);
			}
		}
		else{
			for(int i = 0;i<chapters.length;i++){				
				regions = getChapterIcon(i);
				chapters[i].unlock = regions[0];
				chapters[i].lock = regions[1];
			}
		}
		if(levels != null){
			for(int i = 0; i< chapters.length; i++){
				int starTotal = 0;
				for(int j=0;j<levels[i].starCollect.length;j++){									
					if(levels[i].starCollect[j]!=-1)
						starTotal += levels[i].starCollect[j];
				}
				if(chapters[i].isUnLock)
					chapters[i].starCollect = starTotal;
			}
		}
	}
	
	public int getTotalStarAllChapter(){
		int total = 0;
	if(levels != null){
		for(int i = 0; i< chapters.length; i++){
			int starTotal = 0;
			for(int j=0;j<levels[i].starCollect.length;j++){									
				if(levels[i].starCollect[j]!=-1)
					starTotal += levels[i].starCollect[j];
			}
			if(chapters[i].isUnLock)
				chapters[i].starCollect = starTotal;
		}
	}
	
	for(int i=0;i<chapters.length;i++){
		if(chapters[i].isUnLock){
			total+=chapters[i].starCollect;
		}
	}
	return total;
	
	}
	public TextureRegion[] getChapterIcon(int chapter){
		// Thêm truoừng cho chapter bonus
		TextureRegion[] regions = new TextureRegion[2];
		switch (chapter) {
		case 0:
			regions[0] = ctr.a.pika1Region;
			regions[1] = ctr.a.pika1Region;
			break;
		case 1:
			regions[0] = ctr.a.pika2Region;
			regions[1] = ctr.a.pika2Region;
			break;
		case 2:
			regions[0] = ctr.a.pika3Region;
			regions[1] = ctr.a.pika3Region;
			break;
		case 3:			
			regions[0] = ctr.a.pika4Region;
			regions[1] = ctr.a.pika4Region;
			break;
		case 4:
			regions[0] = ctr.a.pika5Region;
			regions[1] = ctr.a.pika5Region;
			break;
		case 5:
			regions[0] = ctr.a.pika6Region;
			regions[1] = ctr.a.pika6Region;
			break;
		case 6:				
			regions[0] = ctr.a.pika7Region;
			regions[1] = ctr.a.pika7Region;
			break;
		case 7:				
			regions[0] = ctr.a.pika8Region;
			regions[1] = ctr.a.pika8Region;
			break;
		}
		return regions;
	}
	
	public void getLevel(){

		String prevData = null;
		if(ctr.androidHelper.checkFileExist("/sdcard/data/ogme/level2.txt")){			
		}
		else{
			if(ctr.androidHelper.checkFileExist("/sdcard/data/ogme/level.txt")){				
				prevData = ctr.androidHelper.getStringFile("level.txt", "");
			}		
		}
		
		String data = ctr.androidHelper.getStringFile("level2.txt", prevData!=null?prevData+"|7,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1":"0,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|2,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|3,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|4,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|5,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|6,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|7,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1");
		
		//String data = ctr.androidHelper.getStringFile("level.txt", "0,20,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1|1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|2,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|3,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|4,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|5,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1|6,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1");
				
		TextureRegion[] regions;
		
		if(data!=null && levels == null ){
			String[] level = ctr.stringHelper.split(data, '|');		
			levels = new LevelInfo[level.length];
			int chapter; int maxLevel;			
			for(int i=0;i<level.length;i++){
				int[] stars = new int[20];
				String[] details = ctr.stringHelper.split(level[i], ',');
				chapter = Integer.parseInt(details[0]);
				maxLevel = Integer.parseInt(details[1]);
				regions = getLevelIcon(chapter);
				for(int j=0; j < stars.length; j++){
					stars[j] = Integer.parseInt(details[2+j]);
				}				
				levels[i] = new LevelInfo(stars, maxLevel, regions[0], regions[1]);
			}			
		}		
		else{
			for(int i = 0;i<levels.length;i++){			
				regions = getLevelIcon(i);
				levels[i].unlock = regions[0];
				levels[i].lock = regions[1];
			}
		}
	}
	
	public TextureRegion[] getLevelIcon(int chapter){
		// Thêm case cho chapter bonus
		TextureRegion[] regions = new TextureRegion[2];
		switch (chapter) {
		case 0:						
			regions[0] = ctr.a.ball1Region;
			break;
		case 1:
			regions[0] = ctr.a.ball2Region;
			break;
		case 2:						
			regions[0] = ctr.a.ball3Region;
			break;
		case 3:
			regions[0] = ctr.a.ball4Region;
			break;
		case 4:						
			regions[0] = ctr.a.ball5Region;
			break;
		case 5:
			regions[0] = ctr.a.ball6Region;
			break;
		case 6:						
			regions[0] = ctr.a.ball2Region;
			break;
		case 7:						
			regions[0] = ctr.a.ball4Region;
			break;
		}
		regions[1] = ctr.a.ball0Region;

		return regions;
	}
	
	public void saveAllChapter(){		
		if(levels != null){
			for(int i = 0; i< chapters.length; i++){
				int starTotal = 0;
				for(int j=0;j<levels[i].starCollect.length;j++){									
					if(levels[i].starCollect[j]!=-1)
						starTotal += levels[i].starCollect[j];
				}
				if(chapters[i].isUnLock)
					chapters[i].starCollect = starTotal;
			}
		}
	
		String chap="";	
		for(int i = 0; i< chapters.length; i++){
			if(i!=0)
				chap += "|";
			chap += i+","+(chapters[i].isUnLock?"1":"0")+","+chapters[i].starToUnLock+","+chapters[i].starCollect;			
		}		
		ctr.androidHelper.saveFile("chapter2.txt", chap);
		
		if(levels!=null){
		String le="";
		for(int i = 0; i< levels.length; i++){
			if(i!=0)
				le += "|";
			le += i+","+(levels[i].maxLevel);
			for(int j=0; j<levels[i].starCollect.length;j++){				
				le+=","+levels[i].starCollect[j];
			}
		}
		ctr.androidHelper.saveFile("level2.txt", le);
		}
	}
	
	public void getMap(){
		if(maps == null){
			maps = new Vector<MapInfo>();			
			String mapStr =   "map1,7,"+
					  "110011110011"+
					  "100111111001"+
					  "001101101100"+
					  "101111111101"+
					  "101011110101"+
					  "001101101100"+
					  "100110011001"+
					  "011011110110"+"|"+
					  "map2,1,"+
					  "111111111111"+
					  "100000000001"+
					  "100000000001"+
					  "100000000001"+
					  "100000000001"+
					  "100000000001"+
					  "100000000001"+
					  "111111111111";
			if(ctr.d.isLDPI){				
				mapStr =   "map1,7,"+
						  "1001111001"+
						  "0011111100"+
						  "0110110110"+
						  "0111111110"+
						  "0101111010"+
						  "0110110110"+
						  "|"+
						  "map2,1,"+
						  "1111111111"+
						  "1000000001"+
						  "1000000001"+
						  "1000000001"+
						  "1000000001"+
						  "1111111111";
			}
			
			String prevData = null;
			if(ctr.androidHelper.checkFileExist("/sdcard/data/ogme/map2.txt")){			
			}
			else{
				if(ctr.androidHelper.checkFileExist("/sdcard/data/ogme/map.txt")){				
					prevData = ctr.androidHelper.getStringFile("map.txt", "");
				}		
			}
			
			String mapDataStr = ctr.androidHelper.getStringFile("map2.txt", 		
				prevData!=null?prevData:mapStr);
		String[] mapData = ctr.stringHelper.split(mapDataStr, '|');
		if(mapData==null){
			if(mapDataStr!=null && !mapDataStr.equals("")){
				mapData = new String[1];
				mapData[0] = mapDataStr;
			}
		}
		int chapter;
		String name;
		String map;
		if(mapData!=null){
			for(int i=0;i<mapData.length;i++){
				String[] details = ctr.stringHelper.split(mapData[i],',');
				name = details[0];
				chapter = Integer.parseInt(details[1]);
				map = details[2];
				addMap(name, chapter, map);
			}
		}
		}
		else{			
			for(int i = 0; i<maps.size(); i++){		
				int chapter = maps.elementAt(i).chapter;
				maps.elementAt(i).bg = getBgChapter(chapter);
				maps.elementAt(i).square = ctr.a.boundSquare;
				maps.elementAt(i).item = getIconTemplate(chapter);
			}
		}
	}	

	public TextureRegion getBgChapter(int chapter){		
		return ctr.a.bgAllMap;
	}
	
	public TextureRegion getIconTemplate(int chapter){
		return ctr.a.templateIcon[chapter];
	}
	
	public void addMap(String name, int chapter, String map) {
		int maxRow = 8, maxCol = 12;
		if(ctr.d.isLDPI){
			maxRow = 6;
			maxCol = 10;
		}
		int numberTypePika;
		int time;
		int stylePlay;
		int maxTypePika = 0;
		TextureRegion bg = null, square = null, item = null;

		int total = 0;
		for (int j = 0; j < map.length(); j++) {
			if ("1".equals(map.substring(j, j + 1))) {
				total++;
			}
		}
		bg = getBgChapter(chapter);
		square = ctr.a.boundSquare;
		item = getIconTemplate(chapter);
		maxTypePika = maxTypeIcon[chapter];
		int two = total / 2;
		numberTypePika = two - new Random().nextInt(two / 2);
		if (numberTypePika > maxTypePika) {
			numberTypePika = maxTypePika;
		}
		time = (int) ((two * 3 + numberTypePika * 0.5) * 1000);
		stylePlay = new Random().nextInt(7);
		maps.add(new MapInfo(name, chapter, map, maxRow, maxCol, time,
				numberTypePika, stylePlay, bg, square, item));
	}
	
	public void changeChapterMapDraw(int index, int chapter){
			maps.elementAt(index).chapter = chapter;
			TextureRegion bg=null, square=null, item=null;
			maps.elementAt(index).bg = getBgChapter(chapter);
			maps.elementAt(index).square = ctr.a.boundSquare;
			maps.elementAt(index).item = getIconTemplate(chapter);
	}
	
	public void saveAllMap(){
		String map = "";
		for(int i=0; i< maps.size();i++){			
			if(i!=0)
				map+="|";
			map += maps.elementAt(i).name+",";
			map += maps.elementAt(i).chapter+",";
			map += maps.elementAt(i).map;
		}		
		ctr.androidHelper.saveFile("map2.txt", map);
	}
	
	public boolean isLogined(){
		return (isCheckAvatar&&!isNewAvatarNotSync);
		//return isLogined;
	}
	
	public void init(){
		
		
		BaseGameScreen.tickTimeLogined = 0;
		
		isLogout = false;
		
		nameB = "";
		
		ctr.d.backLis = new Vector<BackListener>();
		maxTypeIcon = new int[8];
		maxTypeIcon[0] = 32;
		maxTypeIcon[1] = 33;
		maxTypeIcon[2] = 17;
		maxTypeIcon[3] = 36;
		maxTypeIcon[4] = 25;
		maxTypeIcon[5] = 16;
		maxTypeIcon[6] = 31;
		maxTypeIcon[7] = 77;
		
		gifts = null;
		gifts = new Vector<Gift>();
		
		dailyGifts = null;
		dailyGifts = new Vector<DailyGift>();
		
		timeAvatar = null;
		isNewAvatarNotSync = false;
		isSyncingNewAvatar = false;
		isSyncedNewAvatar = false;
		
		isChangeAvatar = false;
		
		isLoadingLazy = false;
		lazyLoad = new Vector<LazyLoadImage>();
		
		isLoadingGameAdvertise = false;
		gameAdvertiseLoad = new Vector<GameAdvertise>();
		
		isHasAccount=false;
		isMusic = true;
		isSound = true;
		isLogined = false;
		isHasSessionId = false;
		
		isSendingGetSessionId = false;
		isNetworkAvaiable = false;
				
		isSendingAvatar = false;
		isCheckAvatar = false;
		
		isSendingLogin = false;
		isFirstInVS = true;
		money = 0;
		name = "";	
		email = "";
		pass = "";
		speedPlay = 0.0f;
		passPre = "";
		namePre = "";
		emailPre = ctr.androidHelper.getEmail();
		
		isLoginedFB = false;
	}
	
	public void dispose(){
		
		isLogout = false;
		
		nameB = null;
		
		isNetworkAvaiable = false;
		isSendingLogin = false;		
		isFirstInVS = true;
		isSendingGetSessionId = false;
		isHasSessionId = false;
		
		isLoadingLazy = false;
		lazyLoad.removeAllElements();
		lazyLoad = null;
		
		isLoadingGameAdvertise = false;
		gameAdvertiseLoad.removeAllElements();
		gameAdvertiseLoad = null;
		
		gifts.removeAllElements();
		gifts = null;
		
		dailyGifts.removeAllElements();
		dailyGifts = null;
		
		timeAvatar = null;
		isNewAvatarNotSync = false;
		isSyncingNewAvatar = false;
		isSyncedNewAvatar = false;
				
		isSendingAvatar = false;
		isCheckAvatar = false;
		
		isLogined = false;
		isHasAccount=false;
		isMusic = false;
		isSound = false;
		
		isChangeAvatar = false;

		money = 0;
		name = null;
		email = null;
		pass = null;
		chapters = null;
		levels = null;
		if(maps!=null)
			maps.removeAllElements();
		maps = null;
		if(backLis!=null)
			backLis.removeAllElements();
		backLis = null;
		if(maxTypeIcon!=null)
			maxTypeIcon = null;
		speedPlay = 0.0f;
		passPre = null;
		namePre = null;
		emailPre = null;
		
		isLoginedFB = false;
		
		isNoelWeek = false;
	}
	
	public int getChapter(int level){
		return (level-1)/20;
	}	
	
	public int getTypeAchievement(){
		return getTypeAchievement(achievement);
	}
	
	public int getTypeAchievement(String achievement){
		if(achievement.startsWith("N")){
			return 0;
		}
		else if(achievement.startsWith("T")){
			return 1;
		}
		else if(achievement.startsWith("C")){
			if(achievement.startsWith("Cao thủ")){
				return 2;
			}
			else{
				return 3;
			}
		}
		else{
			return 4;
		}
	}
	
	public boolean isLoadingLazy;
	public Vector<LazyLoadImage> lazyLoad;
	
	public boolean isLoadingGameAdvertise;
	public Vector<GameAdvertise> gameAdvertiseLoad;
	
	public void clearAllNotify(){
		ctr.androidHelper.saveFile("notify", "");
	}
	
	public void saveNotify(int type, String content, String link, String path){
		String current = ctr.androidHelper.getStringFile("notify", "");
		current += type+"*"+content+"*"+link+"*"+path+"*"+"#";
		ctr.androidHelper.saveFile("notify", current);
	}
	
	boolean isLoadedNotify = false;
	public void getNotifyOffline(){
		if(isLoadedNotify)
			return;
		isLoadedNotify = true;
		ctr.autoRunText.notify.removeAllElements();
		ctr.d.gameAdvertiseLoad.removeAllElements();
		String current = ctr.androidHelper.getStringFile("notify", "");
		if(!current.equals("")){
			String[] details = ctr.stringHelper.split(current, '#');
			for(int i=0;i<details.length;i++){
				if(details[i]!=null){
					if(details[i].length()>5&&!details[i].equals("")){					
						String[] data = ctr.stringHelper.split(details[i], '*');
						if(data[0].equals("0")){
							ctr.autoRunText.addNotify(0,data[1], null, null);
						}
						else{
							if(ctr.androidHelper.checkFileExist("/sdcard/"+data[3])){
								ctr.autoRunText.addNotify(1,data[1], data[3], data[2]);
							}
						}
					}
				}
			}
		}
	}
	//=============VS2RESULT==========
	public IMAction vs2ResultAction = null;
}
